////捕捉生物
const captureItem = 'kubejs:soulgem_empty'
const capturedItem = {name:'kubejs:soulgem',displayName:'缚魂之石'}
const pronounTest = (s,c) => {
    if (c) {
        return ''
    } else if (/[AEIOU].*/.test(s)) {
        return ''
    } else {
        return ''
    }
}
onEvent('item.right_click', event => {
    if (event.item.id === capturedItem.name) {
        event.server.runCommandSilent(`summon ${event.item.nbt.CapturedEntity} ${event.player.x} ${event.player.y + 0.7} ${event.player.z} ${event.item.nbt.CapturedData}`)
        event.item.count --
event.player.give('kubejs:soulgem_empty') 

    }
})
onEvent('item.entity_interact', event => {
    if (event.item.id === captureItem 
	&& !event.target.player 
	&& event.target.type != 'minecraft:ender_dragon'
	&& event.target.type != 'minecraft:wither'
	&& event.target.type != 'minecraft:item'
	&& event.target.type != 'minecraft:item_frame'
	&& event.target.type != 'minecraft:falling_block'
	&& event.target.type != 'minecraft:armor_stand'
	&& event.target.type != 'minecraft:end_crystal'
	&& event.target.type != 'minecraft:minecart'
	&& event.target.type != 'minecraft:tnt'
	&& event.target.type != 'minecraft:leash_knot'
	&& event.target.type != 'minecraft:painting') { //Exclude the ender dragon as it doesn't like being tped around like this
        event.item.count --
        let nbt = event.target.fullNBT
        delete nbt.UUID

		
        event.server.runCommandSilent(`summon minecraft:item ${event.target.x} ${event.target.y} ${event.target.z} {PickupDelay:10,Motion:[0.0,0.2,0.0],Item:{id:"${capturedItem.name}",Count:1b,tag:{display:{Name:'{"text":"${capturedItem.displayName}","italic":false}',Lore:['{"text":"束缚着${pronounTest(event.target.name, nbt.CustomName)}${event.target.name}的灵魂"}']},CapturedEntity: "${event.target.type}", CapturedData: ${nbt}}}}`)
		
		event.server.runCommandSilent(`gamerule showDeathMessages false`)
        event.target.y=-400
		event.target.kill()
		event.server.runCommandSilent(`gamerule showDeathMessages true`)
        	
         //don't kill it immediately otherwise the death animation will be visible. The void will finish it off
    }
})

onEvent('item.tooltip', e => {
  e.addAdvanced('kubejs:test_item', (item, advanced, text) => {
    if (!e.isShift()) {
      text.add(1, [Text.of('Hold ').gold(), Text.of('Shift ').yellow(), Text.of('to see more info.').gold()])
    }
    if (e.isShift()) {
      text.add(1, [Text.of('Default: '), Text.of('50 '), Text.of('mB/t')])
      text.add(2, [Text.of('Basic: '), Text.of('100 '), Text.of('mB/t')])
      text.add(3, [Text.of('Improved: ').gold(), Text.of('500 ').yellow(), Text.of('mB/t').gold()])
      text.add(4, [Text.of('Advanced: ').darkAqua(), Text.of('2,000 ').aqua(), Text.of('mB/t').darkAqua()])
      text.add(5, [Text.of('Ultimate: ').darkGray(), Text.of('10,000 ').gray(), Text.of('mB/t').darkGray()])
      text.add(6, [Text.of('Infinity: ').darkPurple(), Text.of('2,147,483,647 ').lightPurple(), Text.of('mB/t').darkPurple()])
    }
  })
})